﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;
namespace WFApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*
             因为实在找不到有手机号码的网站，所以正则匹配的是客服电话
             查了一下 客服电话一般是400-***-****的格式，*代表一个数字
             因为也有规约约束客服电话 所以把匹配手机号改成了匹配客服电话^_^             
             */
            tbEmail.Text = "";
            tbPhone.Text = "";
            try
            {
                string url = tbUrl.Text;
                WebClient client = new WebClient();
                byte[] pageData = client.DownloadData(url);
                string text = Encoding.Default.GetString(pageData);
                string pattern = @"\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}";
                string patternPhone = @"400[\-]?\d{3}[\-]?\d{4}";
                MatchCollection mc = Regex.Matches(text, pattern);
                MatchCollection mcp = Regex.Matches(text, patternPhone);
                foreach (Match match in mc)
                {
                    tbEmail.Text+=match.ToString()+"\r\n";
                }
                foreach(Match matchp in mcp)
                {
                    tbPhone.Text += matchp.ToString() + "\r\n";
                }
            }catch(Exception exp)
            {
                throw exp;
            }           
            
        }

        private void lblphone_Click(object sender, EventArgs e)
        {

        }
    }
}
